<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>

	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            选择发货计划
        </div>
    </header>

	<script id="mrlTemp" type="text/x-dot-template">

		{{~ it:value:index}}
		<li class="aui-list-item" onclick="setInvoiceplan('{{= it[index].code }}');">
			<div class="aui-list-item-inner">
				<div class="aui-list-item-title">{{= it[index].code }}</div>
			</div>
		</li>
		{{~}}

	</script>

	<div class="aui-content">
		<div class="aui-searchbar" id="search">
			<div class="aui-searchbar-input aui-border-radius" tapmode onclick="doSearch()">
				<i class="aui-iconfont aui-icon-search"></i>
				<div class="aui-searchbar-input">
					<form action="javascript:search();">
						<input type="search" placeholder="请输入计划单号" id="search-input">
					</form>
				</div>
				<i class="aui-iconfont aui-icon-roundclosefill" tapmode onclick="clearInput()"></i>
			</div>
			<div class="aui-searchbar-cancel aui-text-info" tapmod onclick="search()">搜索</div>
		</div>

		<ul class="aui-list aui-form-list" style="margin-top: 2.2rem">
			<li class="aui-list-item">
				<div class="aui-list-item-inner">
					<div class="aui-list-item-label">计划日期</div>
					<div class="aui-list-item-input" onclick="timePicker();">
						<input type="text" placeholder="选择日期" class="aui-input" id="plandate">
					</div>
				</div>
			</li>
		</ul>
		<ul class="aui-list aui-list-in" id="mrlListUl">

		</ul>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
	apiready = function () {
		crateDate();
	};

	function crateDate() {
		var date = new Date();
		var year = date.getFullYear();
		var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
		var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
		$("#plandate").val(year + "-" + month + "-" + day);

		search();
	}

	function doSearch() {
		$api.addCls($api.dom(".aui-searchbar"), "focus");
		$api.dom('.aui-searchbar-input input').focus();
	}

	function cancelSearch() {
		$api.removeCls($api.dom(".aui-searchbar.focus"), "focus");
		$api.val($api.byId("search-input"), '');
		$api.dom('.aui-searchbar-input input').blur();
	}

	function clearInput() {
		$api.val($api.byId("search-input"), '');
	}

	//时间选择器
	function timePicker(id) {
		api.openPicker({
			type: 'date',
			date: new Date(),
			title: '选择日期'
		}, function (ret, err) {
			if (ret) {
				var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
				var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
				var date = ret.year + "-" + monthTemp + "-" + dayTemp;
				$("#plandate").val(date);
				search();
			}
		});
	}

	function search() {
		var content = $api.val($api.byId("search-input"));
		cancelSearch();

		var plandate = $("#plandate").val();

		var un = localStorage.getItem("un");
		var serverUrl = localStorage.getItem('serverUrl');
		var url = serverUrl + "/app/getInvoiceplan";

		var data = {
			values: {
				code: content,
				appVersion: api.appVersion,
				plandate: plandate,
				un: un
			}
		};

		api.ajax({
			url: url,
			method: 'post',
			dataType: 'json',
			timeout: 30,
			returnAll: false,
			data: data
		}, function (ret, err) {
			if (ret) {
				var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var mydata = eval(myobj.list);
                    var evaluation = doT.template($api.dom('#mrlTemp').innerHTML);
                    $api.dom('#mrlListUl').innerHTML = evaluation(mydata);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
			}
		});
	}

	function setInvoiceplan(code) {

		api.closeWin();
        var nameR = api.pageParam.name;
        api.execScript({
            name: nameR,
            script: 'setInvoiceplan("' + code + '")'
        });
	}

	function closeWin(){
		api.closeWin();
	}
</script>

</html>